// import { format } from 'date-fns';

import {number} from "echarts";

const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
const DATE_FORMAT = 'YYYY-MM-DD ';

export function formatToDateTime(date: Date | number, formatStr = DATE_TIME_FORMAT): string {
    return formatDate(date, formatStr);
}

export function formatToDate(date: Date | number, formatStr = DATE_FORMAT): string {
    return formatDate(date, formatStr);
}

function formatDate(time: Date | number, formatStr: string): string {
    let date
    if (time instanceof Date) {
        date = time
    } else {
        date = new Date(time);
    }
    let YY = date.getFullYear();
    let MM = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    let DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    let hh = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
    let mm = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    let ss = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
    // 这里修改返回时间的格式
    if (formatStr === DATE_FORMAT) {
        return YY + "-" + MM + "-" + DD
    } else if (formatStr === DATE_TIME_FORMAT) {
        return YY + "-" + MM + "-" + DD + " " + hh + ":" + mm + ":" + ss;
    }
    return YY + "-" + MM
}
